package com.ysstech.common.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * Swagger2API文档的配置
 * http://127.0.0.1:7001/swagger-ui.html
 */
@Configuration
@EnableSwagger2
public class Swagger2Config {
    //取配置文件的值
    @Value("${yss.swagger.base-package}")
    private String basePackage;
    @Value("${yss.swagger.title}")
    private String title;
    @Value("${yss.swagger.description}")
    private String description;
    @Value("${yss.swagger.version}")
    private String version;

    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage(basePackage))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title(title)
                .description(description)
                .version(version)
                //.termsOfServiceUrl("http://www.baidu.com")
                //.contact(new Contact("123", "http://www.baidu.com", "123@163.com"))
                .build();
    }
}
